home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / puma.lha / puma / m2c / Tree2.c < prev    next >
C/C++ Source or Header  |  1992-09-25  |  6KB  |  288 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_System
  4. #include "System.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_General
  8. #include "General.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Memory
  12. #include "Memory.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_DynArray
  16. #include "DynArray.h"
  17. #endif
  18.  
  19. #ifndef DEFINITION_IO
  20. #include "IO.h"
  21. #endif
  22.  
  23. #ifndef DEFINITION_Layout
  24. #include "Layout.h"
  25. #endif
  26.  
  27. #ifndef DEFINITION_StringMem
  28. #include "StringMem.h"
  29. #endif
  30.  
  31. #ifndef DEFINITION_Strings
  32. #include "Strings.h"
  33. #endif
  34.  
  35. #ifndef DEFINITION_Idents
  36. #include "Idents.h"
  37. #endif
  38.  
  39. #ifndef DEFINITION_Texts
  40. #include "Texts.h"
  41. #endif
  42.  
  43. #ifndef DEFINITION_Sets
  44. #include "Sets.h"
  45. #endif
  46.  
  47. #ifndef DEFINITION_Positions
  48. #include "Positions.h"
  49. #endif
  50.  
  51. #ifndef DEFINITION_Tree
  52. #include "Tree.h"
  53. #endif
  54.  
  55. #ifndef DEFINITION_Tree2
  56. #include "Tree2.h"
  57. #endif
  58.  
  59.  
  60. typedef Tree_tTree *yyPtrtTree;
  61. static IO_tFile yyf;
  62. static SHORTCARD yyLabel;
  63. static SHORTCARD yyKind;
  64. static CHAR yyc;
  65. static Strings_tString yys;
  66. #define yyInitTreeStoreSize    32
  67. static LONGINT yyTreeStoreSize;
  68. static struct S_1 {
  69.     Tree_tTree A[50000 + 1];
  70. } *yyTreeStorePtr;
  71. static INTEGER yyLabelCount;
  72. static SHORTINT yyRecursionLevel;
  73. static SHORTCARD yyMapToLabel ARGS((Tree_tTree yyTree));
  74. static Tree_tTree yyMapToTree ARGS((SHORTCARD yyLabel));
  75. #define yyNil    ((CHAR)'\374')
  76. #define yyNoLabel    ((CHAR)'\375')
  77. #define yyLabelDef    ((CHAR)'\376')
  78. #define yyLabelUse    ((CHAR)'\377')
  79. static void yyGetTree2 ARGS((yyPtrtTree yyt));
  80. static void yyGet ARGS((BYTE yyx[], LONGCARD ));
  81. static void yyGetIdent ARGS((Idents_tIdent *yyi));
  82.  
  83.  
  84. static SHORTCARD yyMapToLabel
  85. # ifdef __STDC__
  86. (Tree_tTree yyTree)
  87. # else
  88. (yyTree)
  89. Tree_tTree yyTree;
  90. # endif
  91. {
  92.   INTEGER yyi;
  93.  
  94.   {
  95.     LONGINT B_1 = 1, B_2 = yyLabelCount;
  96.  
  97.     if (B_1 <= B_2)
  98.       for (yyi = B_1;; yyi += 1) {
  99.         if (yyTreeStorePtr->A[yyi] == yyTree) {
  100.           return yyi;
  101.         }
  102.         if (yyi >= B_2) break;
  103.       }
  104.   }
  105.   INC(yyLabelCount);
  106.   if (yyLabelCount == yyTreeStoreSize) {
  107.     DynArray_ExtendArray((ADDRESS *)&yyTreeStorePtr, &yyTreeStoreSize, (LONGINT)sizeof(Tree_tTree));
  108.   }
  109.   yyTreeStorePtr->A[yyLabelCount] = yyTree;
  110.   return yyLabelCount;
  111. }
  112.  
  113. static Tree_tTree yyMapToTree
  114. # ifdef __STDC__
  115. (SHORTCARD yyLabel)
  116. # else
  117. (yyLabel)
  118. SHORTCARD yyLabel;
  119. # endif
  120. {
  121.   return yyTreeStorePtr->A[yyLabel];
  122. }
  123.  
  124. Tree_tTree Tree2_GetTree2
  125. # ifdef __STDC__
  126. (IO_tFile yyyf)
  127. # else
  128. (yyyf)
  129. IO_tFile yyyf;
  130. # endif
  131. {
  132.   Tree_tTree yyt;
  133.  
  134.   yyf = yyyf;
  135.   if (yyRecursionLevel == 0) {
  136.     yyLabelCount = 0;
  137.   }
  138.   INC(yyRecursionLevel);
  139.   yyGetTree2((yyPtrtTree)ADR(yyt));
  140.   DEC(yyRecursionLevel);
  141.   return yyt;
  142. }
  143.  
  144. static void yyGetTree2
  145. # ifdef __STDC__
  146. (yyPtrtTree yyt)
  147. # else
  148. (yyt)
  149. yyPtrtTree yyt;
  150. # endif
  151. {
  152.   for (;;) {
  153.     yyc = IO_ReadC(yyf);
  154.     switch (yyc) {
  155.     case yyNil:;
  156.       *yyt = Tree_NoTree;
  157.       return;
  158.       break;
  159.     case yyLabelUse:;
  160.       yyGet((WORD *)&yyLabel, (LONGCARD)sizeof(yyLabel));
  161.       *yyt = yyMapToTree(yyLabel);
  162.       return;
  163.       break;
  164.     case yyLabelDef:;
  165.       yyGet((WORD *)&yyLabel, (LONGCARD)sizeof(yyLabel));
  166.       yyKind = ORD(IO_ReadC(yyf));
  167.       *yyt = Tree_MakeTree(yyKind);
  168.       if (yyLabel != yyMapToLabel(*yyt)) {
  169.         IO_WriteS((System_tFile)IO_StdError, (STRING)"Tree2: error in GetTree2", 24L);
  170.         IO_WriteNl((System_tFile)IO_StdError);
  171.         (*Tree_yyExit)();
  172.       }
  173.       break;
  174.     default :
  175.       yyKind = ORD(yyc);
  176.       *yyt = Tree_MakeTree(yyKind);
  177.       break;
  178.     }
  179.     switch (yyKind) {
  180.     case Tree_Class:;
  181.       yyGetIdent(&(*yyt)->U_1.V_5.Class.Name);
  182.       yyGet((WORD *)&(*yyt)->U_1.V_5.Class.Properties, (LONGCARD)sizeof((*yyt)->U_1.V_5.Class.Properties));
  183.       yyGetTree2((yyPtrtTree)ADR((*yyt)->U_1.V_5.Class.Attributes));
  184.       yyGetTree2((yyPtrtTree)ADR((*yyt)->U_1.V_5.Class.Extensions));
  185.       yyGetTree2((yyPtrtTree)ADR((*yyt)->U_1.V_5.Class.BaseClass));
  186.       yyt = (yyPtrtTree)ADR((*yyt)->U_1.V_5.Class.Next);
  187.       break;
  188.     case Tree_AttrOrAction:;
  189.       yyt = (yyPtrtTree)ADR((*yyt)->U_1.V_8.AttrOrAction.Next);
  190.       break;
  191.     case Tree_Child:;
  192.       yyGetIdent(&(*yyt)->U_1.V_9.Child.Name);
  193.       yyGetIdent(&(*yyt)->U_1.V_9.Child.Type);
  194.       yyGet((WORD *)&(*yyt)->U_1.V_9.Child.Properties, (LONGCARD)sizeof((*yyt)->U_1.V_9.Child.Properties));
  195.       yyt = (yyPtrtTree)ADR((*yyt)->U_1.V_9.Child.Next);
  196.       break;
  197.     case Tree_Attribute:;
  198.       yyGetIdent(&(*yyt)->U_1.V_10.Attribute.Name);
  199.       yyGetIdent(&(*yyt)->U_1.V_10.Attribute.Type);
  200.       yyGet((WORD *)&(*yyt)->U_1.V_10.Attribute.Properties, (LONGCARD)sizeof((*yyt)->U_1.V_10.Attribute.Properties));
  201.       yyt = (yyPtrtTree)ADR((*yyt)->U_1.V_10.Attribute.Next);
  202.       break;
  203.     case Tree_ActionPart:;
  204.       yyt = (yyPtrtTree)ADR((*yyt)->U_1.V_11.ActionPart.Next);
  205.       break;
  206.     default :
  207.       return;
  208.       break;
  209.     }
  210.   } EXIT_1:;
  211. }
  212.  
  213. static void yyGet
  214. # ifdef __STDC__
  215. (BYTE yyx[], LONGCARD O_1)
  216. # else
  217. (yyx, O_1)
  218. BYTE yyx[];
  219. LONGCARD O_1;
  220. # endif
  221. {
  222.   INTEGER yyi;
  223.  
  224.   yyi = IO_Read(yyf, ADR1(yyx), (LONGCARD)((INTEGER)(O_1 - 1) + 1));
  225. }
  226.  
  227. static void yyGetIdent
  228. # ifdef __STDC__
  229. (Idents_tIdent *yyi)
  230. # else
  231. (yyi)
  232. Idents_tIdent *yyi;
  233. # endif
  234. {
  235.   Strings_tString yys;
  236.  
  237.   Strings_ReadL(yyf, &yys);
  238.   *yyi = Idents_MakeIdent(&yys);
  239. }
  240.  
  241. void Tree2_BeginTree2
  242. # ifdef __STDC__
  243. ()
  244. # else
  245. ()
  246. # endif
  247. {
  248. }
  249.  
  250. void Tree2_CloseTree2
  251. # ifdef __STDC__
  252. ()
  253. # else
  254. ()
  255. # endif
  256. {
  257. }
  258.  
  259. void BEGIN_Tree2()
  260. {
  261.   static BOOLEAN has_been_called = FALSE;
  262.  
  263.   if (!has_been_called) {
  264.     has_been_called = TRUE;
  265.  
  266.     BEGIN_Tree();
  267.     BEGIN_IO();
  268.     BEGIN_System();
  269.     BEGIN_General();
  270.     BEGIN_Memory();
  271.     BEGIN_DynArray();
  272.     BEGIN_IO();
  273.     BEGIN_Layout();
  274.     BEGIN_StringMem();
  275.     BEGIN_Strings();
  276.     BEGIN_Idents();
  277.     BEGIN_Texts();
  278.     BEGIN_Sets();
  279.     BEGIN_Positions();
  280.     BEGIN_Tree();
  281.  
  282.     yyRecursionLevel = 0;
  283.     yyTreeStoreSize = yyInitTreeStoreSize;
  284.     DynArray_MakeArray((ADDRESS *)&yyTreeStorePtr, &yyTreeStoreSize, (LONGINT)sizeof(Tree_tTree));
  285.     Tree2_BeginTree2();
  286.   }
  287. }
  288.